class Vector:

    def __new__(self, *args, **kwargs):

        instance = super().__new__(self)
        return instance

    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        print("调用print,和str内置函数会执行这里")
        return f"Vector({self.x}, {self.y})"

    def __repr__(self):
        return f"Vector({self.x}, {self.y})"

    def __add__(self, other):
        print("调用+运算符加法会执行这里")
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, scalar):
        return Vector(self.x * scalar, self.y * scalar)

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def __lt__(self, other):
        return self.magnitude() < other.magnitude()

    def __len__(self):
        return 2  # 总是2D向量

    def __getitem__(self, index):
        if index == 0:
            return self.x
        elif index == 1:
            return self.y
        else:
            raise IndexError("Vector index out of range")

    def magnitude(self):
        return (self.x**2 + self.y**2) ** 0.5


# 使用示例
v1 = Vector(2, 3)
v2 = Vector(4, 5)

print(v1)  # Vector(2, 3)
print(v1 + v2)  # Vector(6, 8)
print(v1 * 3)  # Vector(6, 9)
print(v1 == Vector(2, 3))  # True
print(v1[0])  # 2
print(v1.magnitude())  # 3.605551275463989
